package com.shengyuan.manage_os.old.ying.boce.util;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

//import org.ksoap2.serialization.SoapObject;

/**
 * soapObject->javaBean转化工具
 * @author zjf
 *
 */
public class SoapObjectUtil {
	/**
	 * soap转化为javabean
	 * @param <T>
	 * @param clazz
	 * @param soapObject
	 * @return
	 * @throws IllegalArgumentException
	 * @throws SecurityException
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 * @throws NoSuchMethodException
	 * @throws InstantiationException
	 */
//	public static <T> T soapToPojo(Class<T> clazz, SoapObject soapObject)
//			throws IllegalArgumentException, SecurityException,
//			IllegalAccessException, InvocationTargetException,
//			NoSuchMethodException, InstantiationException {
//		
//		Field[] fields = clazz.getDeclaredFields();
//		Object obj = clazz.newInstance();
//		for (Field field : fields) {
//			Object objnew = soapObject.getProperty(field.getName()) ;
//			field.set(obj, objnew.toString());
//			
//		}
////		for (Field f : fields) {
////			String method = "set" + f.getName().substring(0, 1).toUpperCase()
////					+ f.getName().substring(1);
////			if (hasMethod(method,  clazz.getMethods())) {
////				Method method2 = clazz.getMethod(method, new Class[] { f.getType() });
////				Object objnew = soapObject.getProperty(f.getName()) ;
////				method2.invoke( obj,  objnew.toString());
////			}
////		}
//		return (T)obj;
//	}

	private static boolean hasMethod(String methodName, Method[] method) {
		for (Method m : method) {
			if (methodName.equals(m.getName())) {
				return true;
			}
		}
		return false;
	}
}